import {checkPermissionRole} from '@/api/all'

function checkPermission(el, binding) {
  const { value } = binding

  if (value && value instanceof Array) {
    if (value.length > 0) {
      checkPermissionRole({resources: value[0]}).then(res => {
        if(res.data.data == false) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      })
    }
  } else {
    throw new Error(`need roles! Like v-permission="['admin','editor']"`)
  }
}

export default {
  bind (el, binding) {
    checkPermission(el, binding)
  }
}
